Title Banner

Previous Book Contents Book Index Next

Inside Macintosh: QuickDraw GX Printing Extensions and Drivers /
Chapter 3 - Printer Drivers / The QuickDraw GX ImageWriter II Printer Driver Messages


Providing the Application With Printing Options

QuickDraw GX sends the GXDefaultPrinter message when an application creates a job object so that your driver can create new view devices that represent the specific features provided by your printing device. These features include color information. For raster printing devices, the features also include resolution variations; for vector printing devices, the features include pen information. You can override this message to create view devices for your driver. You attach these view devices to the job object, and the application can then access them to determine specific device settings.

The ImageWriter II printer driver provides various printing resolutions and allows the application to print either in black and white or in color. The driver overrides the GXDefaultPrinter message to add two high resolution (144 dpi) view devices for use by applications. This message override, the SD_DefaultPrinter function, is shown in Listing 3-5. The GXDefaultPrinter message is described on page 4-50 in the chapter "Printing Messages."

Listing 3-5 Modifying the default printer object

OSErr SD_DefaultPrinter(gxPrinter thePrinter)
{
   OSErr          anErr;
   gxViewDevice   vd;
   
   /* add the standard view devices first */
   anErr = Forward_GXDefaultPrinter(thePrinter);
   nrequire(anErr, DefaultPrinter);
   
   /* add a 144 b/w view device */
   vd = NewDeviceResolutionViewDevice();

   {
   gxSetColor  theColors[2];
   gxSetColor  *pColor;
   gxColorSet  theSet;
   
   pColor = &theColors[0];
   
   pColor->rgb.red   = 0xFFFF;
   pColor->rgb.green = 0xFFFF;
   pColor->rgb.blue  = 0xFFFF;
   
   pColor++;
   pColor->rgb.red   = 0x0000;
   pColor->rgb.green = 0x0000;
   pColor->rgb.blue  = 0x0000;
   
   theSet = GXNewColorSet(gxRgbSpace, 2, theColors);
   SetViewDeviceColorSet(vd, theSet);
   GXDisposeColorSet(theSet);
   }

   anErr = GXAddPrinterViewDevice(thePrinter, vd);
   nrequire(anErr, FailedAddBWViewDevice);

   /* add a 144 color view device with 8 colors */
   if (PrinterHasColorRibbon())
      {
      gxSetColor  theColors[8];
      gxSetColor  *pColor;
      gxColorSet  theSet;
      short       idx;

      vd = NewDeviceResolutionViewDevice();
      pColor = &theColors[0];
      for (idx = 0; idx < 8; ++idx)
         {
         /* default the color to black */
         pColor->rgb.red   = 0x0000;
         pColor->rgb.green = 0x0000;
         pColor->rgb.blue  = 0x0000;
         /* then fill in the RGB components */
         if (idx & 0x04)
            pColor->rgb.red   = 0xFFFF;
         if (idx & 0x02)
            pColor->rgb.green = 0xFFFF;
         if (idx & 0x01)
            pColor->rgb.blue  = 0xFFFF;
         ++pColor;
         /* move onto the next color */
         }
      theSet = GXNewColorSet(gxRgbSpace, 8, theColors);
      SetViewDeviceColorSet(vd, theSet);
      GXDisposeColorSet(theSet);

      anErr = GXAddPrinterViewDevice(thePrinter, vd);
      nrequire(anErr, FailedAddColorViewDevice);
      }
   
   return(noErr);

/* exception handling */
FailedAddColorViewDevice:
FailedAddBWViewDevice:
   GXDisposeViewDevice(vd);
   
GXDefaultPrinter:
   return(anErr);
}
The SD_DefaultPrinter function first forwards the GXDefaultPrinter message so that the standard view devices can be added, then adds two of its own: a 144 dpi 1-bit view device and a 144 dpi 8-color view device. This function uses a for loop to assign color values that correspond to the eight basic RGB colors. These values are shown in Table 3-5.
Table 3-5 Color values for an eight-color view device for the ImageWriter II printer
Color nameColor indexRed valueGreen valueBlue value
White00xFFFF0xFFFF0xFFFF
Yellow10xFFFF0xFFFF0x0000
Magenta20xFFFF0x00000xFFFF
Red30xFFFF0x00000x0000
Cyan40x00000xFFFF0xFFFF
Green50x00000xFFFF0x0000
Blue60x00000x00000xFFFF
Black70x00000x00000x0000

The SD_DefaultPrinter function calls two local functions, the code for which is found in the QuickDraw GX sample code:


Previous Book Contents Book Index Next

© Apple Computer, Inc.
7 JUL 1996




Navigation graphic, see text links

Main | Page One | What's New | Apple Computer, Inc. | Find It | Contact Us | Help